package thread;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Scanner;

public class ThreadReadFile {
	public static void main(String[] args) {
		threadReadFile();
	}

	private static boolean run=true;

	private static void threadReadFile() {
		Thread t1 = new Thread() {
			@Override
			public void run() {
				try {
					BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(
					"/home/tarena/Desktop/笑话集锦  .txt"),"gbk"));
					String s;
					while (run&&((s=in.readLine())!=null)) {
						System.out.println(s);
						Thread.sleep(1000);
					}
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		};

		Thread t2 = new Thread() {
			@Override
			public void run() {
				Scanner quit = new Scanner(System.in);
				quit.nextLine();
				run = false;
			}
		};

		t1.start();
		t2.start();
		
	}

}
